package org.linlinjava.litemall.db.service;

import org.apache.commons.lang.StringUtils;
import org.linlinjava.litemall.db.dao.AgedmallOrderSerialMapper;
import org.linlinjava.litemall.db.domain.AgedmallOrderSerial;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class AgedmallOrderSerialService {
    @Resource
    private AgedmallOrderSerialMapper agedmallOrderSerialMapper;

    public int add(){
        AgedmallOrderSerial orderSerial = new AgedmallOrderSerial();
        orderSerial.setAddTime(LocalDateTime.now());
        orderSerial.setDeleted(false);
        agedmallOrderSerialMapper.insert(orderSerial);
        return orderSerial.getId();
    }

    public String getAftersaleSn() {
        // 时间戳加自增数据库6位id
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        int number = add();
        return "S" + time + StringUtils.leftPad(number+"", 6, "0");
    }
}
